//
//  UITabBarItem+Theme.m
//  夜间模式
//
//  Created by Burn on 2018/10/22.
//  Copyright © 2018年 buren. All rights reserved.
//

#import "UITabBarItem+Theme.h"
#import <objc/runtime.h>
#import "ThemeManager.h"
#import "UIView+Theme.h"

@implementation UITabBarItem (Theme)

- (void)setType:(id)type{
    objc_setAssociatedObject(self, @selector(type), type, OBJC_ASSOCIATION_ASSIGN);
}

-(id)type{
    return objc_getAssociatedObject(self, @selector(type));
}

/*开始监听*/
- (void)startMonitor{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeColor) name:@"CHANGECOLOR" object:nil];
}


/*设置颜色类型和对应颜色*/
- (void)nightWithType:(ThemeType)type{
    self.type = [NSNumber numberWithInteger:type];
    [self startMonitor];
    [self changeColor];
    
}

/**修改颜色*/
- (void)changeColor{
    
    NSMutableDictionary *selectedt = [NSMutableDictionary dictionary];
//    NSMutableDictionary *normal = [NSMutableDictionary dictionary];
    switch ([self.type integerValue]) {
        case ThemeTypeNormal:
            
            selectedt = [NSMutableDictionary dictionaryWithObject:[ThemeManager shareInstance].themeNormalColor forKey:NSForegroundColorAttributeName];
            [self setTitleTextAttributes:selectedt forState:UIControlStateSelected];
            break;
        case ThemeTypeBlack:
            
            selectedt = [NSMutableDictionary dictionaryWithObject:[ThemeManager shareInstance].themeBlackColor forKey:NSForegroundColorAttributeName];
            [self setTitleTextAttributes:selectedt forState:UIControlStateSelected];
            break;
        case ThemeTypeRed:
            
            selectedt = [NSMutableDictionary dictionaryWithObject:[ThemeManager shareInstance].themeRedColor forKey:NSForegroundColorAttributeName];
            [self setTitleTextAttributes:selectedt forState:UIControlStateSelected];
            break;
        case ThemeTypeClear:
            
            selectedt = [NSMutableDictionary dictionaryWithObject:[ThemeManager shareInstance].themeClearColor forKey:NSForegroundColorAttributeName];
            [self setTitleTextAttributes:selectedt forState:UIControlStateSelected];
            break;
            
        default:
            break;
    }
}

@end
